/**
 * 
 */
package edu.pw.treegrid.server.message;

import java.util.LinkedList;
import java.util.List;

/** 
 *     Sciezka identyfikujaca wezel (obiekt).
 *     Jest postaci atrybut_id =&gt; wartosc.
 *     
 * @author Xalan
 */
public class Path {
	public static final String PATH_SEPARATOR = ";";
	
	private List<Object> path = new LinkedList<Object>();
	
	public Path() {
	}
	
	public Path(Path other) {
		for(Object o : other.getPath()) {
			path.add(o);
		}
	}

	public Path(String path) {
		for(String s: path.split(PATH_SEPARATOR)) {
			addNode(s);
		}
	}
	
	public List<Object> getPath() {
		return path;
	}

	/** 
	 * Dodaje nowy element do sciezki.
	 * @param objectValue
	 */
	public void addNode(Object objectValue) {
		this.path.add(objectValue);
	}

	@Override
	public String toString() {
		return this.path.toString();
	}
	
	public String buildPathString() {
		StringBuilder sb = new StringBuilder();
		
		boolean first = true;
		for(Object s : getPath()) {
			if(!first) {
				sb.append(PATH_SEPARATOR);
			}
			else {
				first = false;
			}
			sb.append(s != null ? s.toString() : "null");
		}
		
		return sb.toString();
	}
}